#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "../lib/error.h"

int main()
{
    pid_t mypid,childpid;

    mypid = getpid();
    fprintf(stderr,"mypid is %ld\n",(long)mypid);

    childpid = fork();
    if (childpid == -1) {
        oops("fail to","fork");
    }

    if (childpid == 0) {
        fprintf(stderr,"I am a child %ld\n",(long)getpid());
    }
    else if (wait(NULL) != childpid) {
        fprintf(stderr,"A signal must have interrupted the wait!\n");
    }
    else {
        fprintf(stderr,"I am a parent %ld with child %ld\n",(long)getpid(),
                (long)childpid);
    }

    return 0;
}

